package dao

import (
	"server/basic/config"
	"server/basic/model"
)

func Login(name string) (doctor model.Dockers, err error) {
	err = config.DB.Where("name=?", name).Find(&doctor).Error
	if err != nil {
		return model.Dockers{}, err
	}
	return doctor, nil
}

func Patient(id int32, state string) (patient []model.Patients, err error) {
	if state == "" {
		err = config.DB.Where("docker_id=?", id).Find(&patient).Error
		if err != nil {
			return nil, err
		}
	} else {
		err = config.DB.Where("docker_id=?", id).Where("patient_state=?", state).Find(&patient).Error
	}
	return patient, err
}

func Patients(id int32) (patient model.Patients, err error) {

	err = config.DB.Where("id=?", id).Find(&patient).Error
	if err != nil {
		return model.Patients{}, err
	}

	return patient, err
}
